using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid;
using DevExpress.Utils;

using DevExpress.XtraEditors.Repository;

using MM.Entities;
using MM.Business;  

namespace MM
{
    public partial class frmTimPhieuXK_KetQua : Form
    {
        string _matau = "";
        string _nguoitao = "";
        string _sConn = "";

        // the delegate the subscribers must implement
        public delegate void ChonPhieuXuatKho(object frmTimPhieuXK_KetQua, ChonPhieuXKEventArgs chonPYCevent);

        // an instance of the delegate
        public ChonPhieuXuatKho chonPXK;

        public frmTimPhieuXK_KetQua(string sConn, List<PHIEU_XUAT_HANG> lstPXK)
        {
            InitializeComponent();
            _sConn = sConn;

            this.InitGrid(lstPXK);
        }
        private void InitGrid(List<PHIEU_XUAT_HANG> lstPXK)
        {
            this.gridControl1.DataSource = lstPXK;
        }

        private void lnkSoPhieuNK_Click(object sender, EventArgs e)
        {
            ColumnView col = (ColumnView)this.gridControl1.FocusedView;
            string mapxk = col.FocusedValue.ToString();
            
            ChonPhieuXKEventArgs pxkevent = new ChonPhieuXKEventArgs(mapxk);

            if (chonPXK != null)
            {
                chonPXK(this, pxkevent);
            }

        }

        private void gridDSVT_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                if (gridDSVT.FocusedRowHandle >= 0)
                {
                    string mapxk = gridDSVT.GetFocusedRowCellValue("MaPhieuXuatHang").ToString();

                    ChonPhieuXKEventArgs pxkevent = new ChonPhieuXKEventArgs(mapxk);

                    if (chonPXK != null)
                    {
                        chonPXK(this, pxkevent);
                    }
                }
            }
        }

    }

    class ChonPhieuXKEventArgs : EventArgs
    {
        public string MaPhieuXuatKho = "";

        public ChonPhieuXKEventArgs(string mapxk)
        {
            MaPhieuXuatKho = mapxk;
        }
    }
}